package com.charry.designlibsample.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.charry.designlibsample.CollapsingToolbarLayoutAct;
import com.charry.designlibsample.R;

/**
 * Created by lichenkan on 15/7/20.
 */
public class MainAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private String[] datas;

    public MainAdapter(Context context) {
        this.context = context;
        datas = context.getResources().getStringArray(R.array.main_list_data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(this.context).inflate(R.layout.simple_item, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        ((ViewHolder)viewHolder).titleView.setText(datas[i]);
    }

    @Override
    public int getItemCount() {
        return datas.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView titleView;

        public ViewHolder(View itemView) {
            super(itemView);
            titleView = (TextView) itemView.findViewById(R.id.item_title);
            titleView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(new Intent(context, CollapsingToolbarLayoutAct.class));
                }
            });
        }
    }
}
